<?php  if (!defined('BASEPATH')) exit('No direct script access allowed');
/**
 * CIHeadStart Environment Helpers
 *
 * @author Casey McLaughlin
 * @package CIHeadStart
 * @link http://code.google.com/p/ciheadstart
 */

// --------------------------------------------------------------------

/**
 * Returns the maximum upload filesize allowed
 * int he current PHP environment as bytes
 *
 * @return int
 */
function get_ini_max_upload_filesize()
{
	$value = trim(ini_get('upload_max_filesize'));
	
	$suffix = strtolower(substr($value, strlen($value)-1));
	$prefix = substr($value, 0, strlen($value)-1);
	
	//PHP.ini sometimes stores values as "2g" or "3k".  If the value is stored that
	//way, then convert it here
	if ($suffix == 'k')
		$output = $prefix * 1024;
	elseif ($suffix == 'm')
		$output = $prefix * 1048576;
	elseif ($suffix == 'g')
		$output = $prefix * 1073741824;
	else
		$output = $value;
	
	return $output;
}

// --------------------------------------------------------------------

/**
 * Returns the maximum memory allowed
 * in the current PHP environment as bytes
 *
 * @return int
 */
function get_ini_max_memory()
{
	$value = trim(ini_get('memory_limit'));
	
	$suffix = strtolower(substr($value, strlen($value)-1));
	$prefix = substr($value, 0, strlen($value)-1);
	
	//PHP.ini sometimes stores values as "2g" or "3k".  If the value is stored that
	//way, then convert it here
	if ($suffix == 'k')
		$output = $prefix * 1024;
	elseif ($suffix == 'm')
		$output = $prefix * 1048576;
	elseif ($suffix == 'g')
		$output = $prefix * 1073741824;
	else
		$output = $value;
	
	return $output;
}

// --------------------------------------------------------------------

/**
 * Checks if current request was sent is an AJAX request
 *
 * This function specifically
 *
 * @return boolean
 */
function is_ajax()
{
	$ci =& get_instance();

	if (isset($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest')
		return TRUE;
	elseif ($this->input->post('is_ajax') && $this->input->post('is_ajax') == 'true')
		return TRUE;
	else
		return FALSE;
}

/* End of file MY_environment_helper.php */
/* Location: ./app/helpers/MY_environment_helper.php */